﻿using System;

namespace WebCrawler
{
    public enum LoadResultType
    {
        Success = 0,
        Error = 1,
        Skip = 2
    }

    public class PageInfo
    {
        private readonly Exception _exception;
        private readonly string _url;
        private readonly string _text;
        private LoadResultType _resultType = LoadResultType.Success;

        private PageInfo(string url)
        {
            _url = url;
            _resultType = LoadResultType.Skip;
        }

        private PageInfo(string url, string text)
        {
            _url = url;
            _text = text;
            _resultType = LoadResultType.Success;
        }

        public PageInfo(string url, Exception exception)
        {
            _url = url;
            _exception = exception;
            _resultType = LoadResultType.Error;
        }

        public static PageInfo Success(string url, string text) { return new PageInfo(url, text); }
        public static PageInfo Error(string url, Exception ex) { return new PageInfo(url, ex); }
        public static PageInfo Skip(string url) { return new PageInfo(url); }

        public LoadResultType ResultType { get { return _resultType; } }
        public bool IsError() { return _resultType == LoadResultType.Error; }
        public bool IsSuccess() { return _resultType == LoadResultType.Success; }
        public bool IsSkip() { return _resultType == LoadResultType.Skip; }

        public string Url { get { return _url; } }
        public string Text { get { return _text; } }
        public Exception Exception { get { return _exception; } }
    }
}